package com.voxel.sense.infomsg.module.user.staff.details;

import com.example.com.common.app.BasePresenter;
import com.example.com.common.factory.data.DataSource;
import com.voxel.sense.infomsg.R;

import cyy.example.com.facotry.Factory;
import cyy.example.com.facotry.net.helper.NetHelper;
import cyy.example.com.facotry.model.api.BaseEntity;
import cyy.example.com.facotry.model.api.response.StaffDetailsEntity;

/**
 * Created by ChenYiYao on 2018/8/3.
 */
public class StaffDetailsPresenter extends BasePresenter<StaffDetailsContract.View>
        implements StaffDetailsContract.Presenter, DataSource.Callback<BaseEntity<StaffDetailsEntity>> {

    public StaffDetailsPresenter(StaffDetailsContract.View view) {
        super(view);
    }


    @Override
    public void doLoadData(String id) {
        NetHelper.searchStaffDetails(id, this);
    }

    @Override
    public void onDataLoaded(BaseEntity<StaffDetailsEntity> data, int reqId) {
        if (mView == null) {
            return;
        }
        if (data.isSuccess()) {
            StaffDetailsEntity staffEntity = data.getData();
            if (staffEntity != null) {
                mView.onRefreshUI(staffEntity);
            } else {
                //请求成功，没有拿到数据
                mView.showError(Factory.app().getString(R.string.data_rsp_error_unknown));
            }
        } else {
            mView.showError(Factory.app().getString(R.string.network_request_error));
        }
        mView.dimissLoading();
    }

    @Override
    public void onDataNotAvailable(String strRes, int reqId) {

        if (mView == null) {
            return;
        }
        mView.showError(Factory.app().getString(R.string.network_request_error));
        mView.dimissLoading();

    }
}
